#define _CRT_SECURE_NO_WARNINGS 1
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;
typedef pair<int, int> PII;
const int N = 100005;
int n;
PII s[N];
int main() {
    scanf("%d", &n);

    for (int i = 1; i <= n; i++)
        scanf("%d%d", &s[i].first, &s[i].second);

    sort(s + 1, s + 1 + n);

    int ans = 1, maxR = s[1].second;
    for (int i = 2; i <= n; i++) {
        if (s[i].first <= maxR) maxR = min(maxR, s[i].second);
        else ans++, maxR = s[i].second;
    }
    printf("%d\n", ans);
    return 0;
}